//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

//====================================================
// Created     : 2004-1-4
// Author      : Fan Dian
// Description : Some test functions for interrupts
//====================================================

#ifndef __ELASTOS_KTESTF_INTERRUPTS_H__
#define __ELASTOS_KTESTF_INTERRUPTS_H__

#include <core.h>
#include <testhlp.h>
#include <../core/inc/_hal/x86/segment.h>

EXTERN GateDescriptor g_idt[]; // Interrupts Description Table
EXTERN irqs_t g_irqsTable[]; // Mask of IDT

//====================================================
// Description  : Test Interrupts Initialization
// Parameters   : None
// Return       : None
//====================================================
inline void TestInterrupts()
{
    uint_t i;

    // print valid IDT entries
    GateDescriptor gdTemp;
    memset(&gdTemp, 0xff, sizeof(GateDescriptor));
    kprintf("variation of idt entries:\n");
    for (i = 0; i < c_uNumberOfIdtEntries; i++) {
        if ((g_idt[i].u16SegmentSelector == gdTemp.u16SegmentSelector) \
            && (g_idt[i].u16Flag == gdTemp.u16Flag)) {
            continue;
        }
        kprintf("    [%d]: segment selector: 0x%04x, flag: 0x%04x\n", i, \
            g_idt[i].u16SegmentSelector, g_idt[i].u16Flag);
        memcpy(&gdTemp, g_idt + i, sizeof(GateDescriptor));
    }

//    // check the stutus of IDT mask
//    for (i = 0; i< NUMBEROF_IPLS + 1; i++) {
//        if ((uint32_t)(g_irqsTable[i]) != 0) break;
//    }
//    if (i >= NUMBEROF_IPLS + 1)
//        kprintf("    g_irqsTable is ok\n");
//    else
//        kprintf("!!!ERROR!!! g_irqsTable is bad\n");
}

#endif // #ifndef __ELASTOS_KTESTF_INTERRUPTS_H__
